using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Daniel.Core.Models.Mapping
{
    public class ProductReviewMap : EntityTypeConfiguration<ProductReview>
    {
        public ProductReviewMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            // Table & Column Mappings
            this.ToTable("ProductReview");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.CustomerId).HasColumnName("CustomerId");
            this.Property(t => t.ProductId).HasColumnName("ProductId");
            this.Property(t => t.IsApproved).HasColumnName("IsApproved");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.ReviewText).HasColumnName("ReviewText");
            this.Property(t => t.Rating).HasColumnName("Rating");
            this.Property(t => t.HelpfulYesTotal).HasColumnName("HelpfulYesTotal");
            this.Property(t => t.HelpfulNoTotal).HasColumnName("HelpfulNoTotal");
            this.Property(t => t.CreatedOnUtc).HasColumnName("CreatedOnUtc");

            // Relationships
            this.HasRequired(t => t.Customer)
                .WithMany(t => t.ProductReviews)
                .HasForeignKey(d => d.CustomerId);
            this.HasRequired(t => t.Product)
                .WithMany(t => t.ProductReviews)
                .HasForeignKey(d => d.ProductId);

        }
    }
}
